package com.ibeeking.found.open.api.feign.fallback;

import com.ibeeking.found.open.api.common.param.OpenAuthModifyTenantIdParam;
import com.ibeeking.found.open.api.common.param.OpenAuthParam;
import com.ibeeking.found.open.api.common.param.OpenAuthCancelParam;
import com.ibeeking.found.open.api.feign.GlobalOpenAuthFeignClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
@Slf4j
public class GlobalOpenAuthFeignFallbackFactory implements FallbackFactory<GlobalOpenAuthFeignClient> {

    @Override
    public GlobalOpenAuthFeignClient create(Throwable throwable) {
        log.error("调用Global服务异常", throwable);
        return new GlobalOpenAuthFeignClient() {
            @Override
            public ResponseResult<Boolean> modifyAuth(OpenAuthParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，开放平台授权更新失败。", false);
            }

            @Override
            public ResponseResult<Boolean> cancelAuth(OpenAuthCancelParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，开放平台授权取消失败。", false);
            }

            @Override
            public ResponseResult<Boolean> modifyAuthTenantId(OpenAuthModifyTenantIdParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，开放平台授权更新授权租户id失败。", false);
            }
        };
    }
}
